package com.tz.online.book.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.online.book.service.IBookService;
import com.tz.online.entity.Pageing;
import com.tz.online.util.BeanFactory;

@WebServlet(name="indexAction",urlPatterns="/book/IndexAction")
public class IndexAction extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1190858625966952077L;
	//通过bean工厂，获得service接口对象
	IBookService bs = (IBookService) BeanFactory.getBean("bookService");
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		//查询出两个精选图书 和三本新书 和三本推荐图书
		Pageing bestBook = bs.queryBookByCondition(1, 2, "1000003");
		Pageing newBook = bs.queryBookByCondition(1, 3, "1000002");
		Pageing tuijianBook = bs.queryBookByCondition(1, 3, "1000001");
		//queryBookByCondition(now,size,condition ) //分页
		
		req.setAttribute("bestBook", bestBook);
		req.setAttribute("newBook", newBook);
		req.getSession().setAttribute("tuijianBook", tuijianBook);
		//转发到index.jsp 去显示
 		
		req.getRequestDispatcher("/jsp/book/index.jsp").forward(req, resp);
		
	}
}
